package com.sll.hosptials.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sll.hosptials.controller.req.AddUserInfoReq;
import com.sll.hosptials.controller.req.IdReq;
import com.sll.hosptials.controller.req.LoginReq;
import com.sll.hosptials.controller.req.UserInfoPageReq;
import com.sll.hosptials.controller.resp.LoginResp;
import com.sll.hosptials.controller.resp.UserDetailResp;
import com.sll.hosptials.controller.resp.UserInfoPageResp;
import com.sll.hosptials.service.UserInfoService;
import com.sll.hosptials.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Api(tags = "用户信息")
@RequestMapping("/userInfo/")
@RestController
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("用户信息分页")
    @PostMapping("/page")
    public Result<Page<UserInfoPageResp>> page(@RequestBody UserInfoPageReq userInfoPageReq) {
        return Result.success(userInfoService.page(userInfoPageReq));
    }

    @ApiOperation("web登录")
    @PostMapping("/login")
//    @Deprecated     接口过时注解，swagger文档中会在接口名上显示直线标志
    public Result<LoginResp> login(@RequestBody LoginReq req) {
        return Result.success(userInfoService.login(req));
    }

    @ApiOperation("新增/编辑用户信息")
    @PostMapping("/addOrUpdateUserInfo")
    public Result<Boolean> addOrUpdateUserInfo(@RequestBody AddUserInfoReq req) {
        return Result.success(userInfoService.addOrUpdateUserInfo(req));
    }

    @ApiOperation("获取用户详情")
    @PostMapping("/userDetail")
    public Result<UserDetailResp> userDetail(@RequestBody IdReq req) {
        return Result.success(userInfoService.userDetail(req));
    }

    @ApiOperation("批量导入用户信息")
    @GetMapping("/importUserInfo")
    public Result<Boolean> importUserInfo(@RequestParam("file") MultipartFile multipartFile) throws IOException {
        return Result.success(userInfoService.importUserInfo(multipartFile));
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public Result<Boolean> delete(@RequestBody IdReq req) {
        return Result.success(userInfoService.delete(req));
    }
}
